/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.xrkol.sharelib.config.HostConfig;


@Entity
@Table
public class Message extends BasicEntity{

    private static final long serialVersionUID = 1L;

    @Id
    @GenericGenerator(name = "hibernate-uuid", strategy = "uuid")
    @GeneratedValue(generator = "hibernate-uuid")
    private String id;
    
    @Lob
    private String content;
    
    private String description;
    
    @Lob
    private String images;
    
    public String[] getImagePaths(){
        return !Strings.isNullOrEmpty(images)? this.images.trim().split("&") : new String[]{};
    }
    
    public String[] getImageUrls(){
        String[] paths = this.getImagePaths();
        return Lists.transform(Lists.newArrayList(paths), new Function<String, String>(){
            @Override
            public String apply(String path) {
                return HostConfig.IMAGE_HOST + path;
            }
            
        }).toArray(new String[paths.length]);
    }
    
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getImages() {
        return images;
    }

    public void setImages(String images) {
        this.images = images;
    }
    
    
    
}
